--[[ ########## Global Screen Dimensions ########## ]--

Use these global variables to position your elements. They are dynamic
to all resolutions. Android devices are usually taller, so use screenTop to
set the position where you expect 0 to be. The iPad is wider than iPhones,
so use screenLeft. Also the width and height need to factor these differences
in as well, so use screenWidth and screenHeight. Lastly, centerX and centerY
are simply global remaps of display.contentCenterX and Y.

:: USAGE ::

    myObject.x, myObject.y = screenX + 10, screenY + 10 -- Position 10 pixels from the top left corner on all devices

    display.newText("centered text", centerX, centerY, 36) -- Center the text

    display.newRect(screenX, screenY, screenWidth, screenHeight) -- Cover the screen, no matter what size

]]--
centerX = display.contentCenterX
centerY = display.contentCenterY
screenX = display.screenOriginX
screenY = display.screenOriginY
screenWidth = display.contentWidth - screenX * 2
screenHeight = display.contentHeight - screenY * 2
screenLeft = screenX
screenRight = screenX + screenWidth
screenTop = screenY
screenBottom = screenY + screenHeight
cache.contentWidth = display.contentWidth
cache.contentHeight = display.contentHeight
display.contentWidth = screenWidth
display.contentHeight = screenHeight

--[[ ########## Global Content Scale and Suffix  ########## ]--

Checks the content scaling and sets a global var "scale". In addition,
if you use sprite sheets and was retina support, append the global "suffix"
variable when calling your datasheet, and it will pull the hi-res version
when it's needed. On the topic of devices and scals, when in the simulator,
the global variable "simulator" is set to true.

]]--

scale, suffix = display.contentScaleX, ""
if scale < 1 then 
    if scale > .5 then 
        suffix = "@1_5x" 
    else 
        suffix = "@2x" 
    end 
end
magicWidth, magicHeight = 380, 570

--[[ ########## Reference Point Shorthand ########## ]--

All this block does it set shorthand notations for all reference points.
The main purpose of this is for passing short values into display objects.

]]

display.tl = display.TopLeftReferencePoint
display.tc = display.TopCenterReferencePoint
display.tr = display.TopRightReferencePoint
display.cl = display.CenterLeftReferencePoint
display.c  = display.CenterReferencePoint
display.cr = display.CenterRightReferencePoint
display.bl = display.BottomLeftReferencePoint
display.bc = display.BottomCenterReferencePoint
display.br = display.BottomRightReferencePoint

--[[ ########## Layers ########## ]]--

---
-- @param parentGroup
-- @return
local createLayers = function(parentGroup, ...)
    local parentGroup = parentGroup;
    local layers = display.newGroup() 
    parentGroup:insert(layers)
    
    layers._db = {}
    
    for i = 1, #arg do
        local theArg = arg[i]
        if(type(theArg) == "string") then
            --print("|--\\ " .. theArg)
            local group = display.newGroup()
            layers._db[#layers._db+1] = group 
            layers[theArg] = group 
            parentGroup:insert( group )
        end		
    end
    
    return layers;
end
display.createLayers = createLayers;

---
-- @param layers
-- @return
local function destroyLayers(layers)
    for i = #layers._db, 1, -1 do
        layers._db[i]:removeSelf()
    end
    self:removeSelf()
end
display.destroyLayers = destroyLayers;
